package com.huawei.appgallery.search.ui;

import android.app.Activity;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.text.style.TypefaceSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.huawei.appgallery.foundation.application.pkgmanage.model.reserve.ReserveDbInfo;
import com.huawei.appgallery.foundation.card.gamereserve.bean.OrderAppCardBean;
import com.huawei.appgallery.search.api.AutoCompleteBtnCardBean;
import com.huawei.appgallery.search.api.view.AutoSearchDownloadButton;
import com.huawei.appgallery.search.impl.bean.AppInfoBean;
import com.huawei.appgallery.search.ui.widget.NormalSearchView.b;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import o.azb;
import o.cdb;
import o.cde;
import o.cuv;
import o.cuv.d;
import o.cuv.f;
import o.cux;
import o.cvc;
import o.ContentManager;
import o.eqx;

public class AutoCompleteTextAdapter extends BaseAdapter {
    private static final String MEDIUM_FONT = "HwChinese-medium";
    private static final String TAG = "AutoCompleteTextAdapter";
    private static String isOrderApp = "1";
    private b listener;
    private Activity mActivity;
    private List<cvc> mFilteredList;
    private LayoutInflater mInflater;
    private String mKeyword = "";

    static class a {
        private static AutoCompleteBtnCardBean ˎ(AppInfoBean appInfoBean) {
            AutoCompleteBtnCardBean autoCompleteBtnCardBean = new AutoCompleteBtnCardBean();
            autoCompleteBtnCardBean.ˏॱ(appInfoBean.ᐝॱ());
            autoCompleteBtnCardBean.ˋॱ(appInfoBean.ॱᐝ());
            autoCompleteBtnCardBean.ˋ(appInfoBean.v_());
            autoCompleteBtnCardBean.ˏˎ(appInfoBean.ॱـ());
            autoCompleteBtnCardBean.ॱ(appInfoBean.ॱॱ());
            autoCompleteBtnCardBean.ˋᐝ(appInfoBean.ॱˌ());
            autoCompleteBtnCardBean.ᐝॱ(appInfoBean.ʽ());
            autoCompleteBtnCardBean.ॱˊ(appInfoBean.ॱˎ());
            autoCompleteBtnCardBean.ˉ(appInfoBean.ͺ());
            autoCompleteBtnCardBean.ॱ(appInfoBean.ʻॱ());
            autoCompleteBtnCardBean.ॱᐝ(appInfoBean.ॱˊ());
            autoCompleteBtnCardBean.ˏ(appInfoBean.ʼ());
            autoCompleteBtnCardBean.ʽ(appInfoBean.ˊॱ());
            autoCompleteBtnCardBean.ॱॱ(appInfoBean.ˏॱ());
            autoCompleteBtnCardBean.ᐝ(appInfoBean.ᐝ());
            autoCompleteBtnCardBean.ˊॱ(appInfoBean.ٴ());
            autoCompleteBtnCardBean.ʻ(appInfoBean.ˊˊ());
            autoCompleteBtnCardBean.ॱˎ(appInfoBean.ˊᐝ());
            autoCompleteBtnCardBean.ˎ(appInfoBean.ॱ());
            autoCompleteBtnCardBean.ˊ(appInfoBean.ˎˎ());
            autoCompleteBtnCardBean.ˎ(appInfoBean.ˋˋ());
            autoCompleteBtnCardBean.ॱ(appInfoBean.ˊ());
            autoCompleteBtnCardBean.ͺ(appInfoBean.ॱᶥ());
            autoCompleteBtnCardBean.showDisclaimer_ = appInfoBean.showDisclaimer_;
            autoCompleteBtnCardBean.gplinkPkgName_ = appInfoBean.gplinkPkgName_;
            autoCompleteBtnCardBean.webApp_ = appInfoBean.webApp_;
            autoCompleteBtnCardBean.genShortcutForWebApp_ = appInfoBean.genShortcutForWebApp_;
            autoCompleteBtnCardBean.jumpToGpOnGMSDevice_ = appInfoBean.jumpToGpOnGMSDevice_;
            autoCompleteBtnCardBean.detailType_ = appInfoBean.detailType_;
            autoCompleteBtnCardBean.showDetailUrl_ = appInfoBean.showDetailUrl_;
            autoCompleteBtnCardBean.ʿ(appInfoBean.ˎͺ());
            try {
                autoCompleteBtnCardBean.ॱ(Long.parseLong(appInfoBean.ॱˋ()));
            } catch (NumberFormatException e) {
                cux.ˏ.ˊ(AutoCompleteTextAdapter.TAG, "getTextAppView(View convertView, FillSearchResultInfo searchItem) " + e.toString());
            }
            return autoCompleteBtnCardBean;
        }

        private static String ॱ(AppInfoBean appInfoBean) {
            if (appInfoBean.ͺˎ() == null || appInfoBean.ͺˎ().size() <= 0) {
                return null;
            }
            return (String) appInfoBean.ͺˎ().get(0);
        }
    }

    static class c {
        private static View ˊ(cvc o_cvc, LayoutInflater layoutInflater, String str, boolean z) {
            View inflate = layoutInflater.inflate(o.cuv.e.ˎ, null);
            if (o_cvc == null || o_cvc.ˊ() == null || TextUtils.isEmpty(o_cvc.ˊ().ॱ())) {
                cux.ˏ.ˊ(AutoCompleteTextAdapter.TAG, "something is null.");
            } else {
                e ˏ = ˏ(inflate);
                ˏ.ˏ().setText(o_cvc.ˊ().ॱ());
                if (z) {
                    ˏ.ˋ().setVisibility(8);
                } else {
                    ˏ.ˋ().setVisibility(0);
                }
                CharSequence charSequence = ˏ.ˏ().getText().toString();
                String toLowerCase = str.toLowerCase(Locale.US);
                int indexOf = charSequence.toLowerCase(Locale.US).indexOf(toLowerCase);
                if (indexOf >= 0) {
                    int length = toLowerCase.length() + indexOf;
                    if (length <= charSequence.length()) {
                        CharSequence spannableStringBuilder = new SpannableStringBuilder(charSequence);
                        spannableStringBuilder.setSpan(new ForegroundColorSpan(ContentManager.getInstant().getContext().getResources().getColor(d.ˊ)), indexOf, length, 34);
                        spannableStringBuilder.setSpan(new TypefaceSpan(ContentManager.getInstant().getContext().getResources().getString(f.ˏ)), indexOf, length, 33);
                        spannableStringBuilder.setSpan(new TypefaceSpan(AutoCompleteTextAdapter.MEDIUM_FONT), indexOf, length, 34);
                        ˏ.ˏ().setText(spannableStringBuilder);
                    }
                }
            }
            return inflate;
        }

        private static e ˏ(View view) {
            e eVar = new e();
            azb.ˏ(view, cuv.b.ʻ);
            eVar.ˎ((TextView) view.findViewById(cuv.b.ˊʻ));
            eVar.ˏ((ImageView) view.findViewById(cuv.b.ॱˎ));
            azb.ˋ(eVar.ˋ());
            return eVar;
        }

        private static View ॱ(cvc o_cvc, LayoutInflater layoutInflater, boolean z, b bVar) {
            View view = null;
            AppInfoBean ˏ = o_cvc.ˏ();
            if (ˏ != null) {
                e ˎ;
                View inflate;
                if (AutoCompleteTextAdapter.isOrderApp.equals(ˏ.ˈ())) {
                    inflate = layoutInflater.inflate(o.cuv.e.ʼॱ, null);
                    view = inflate;
                    ˎ = ˎ(inflate);
                } else {
                    inflate = layoutInflater.inflate(o.cuv.e.ʻॱ, null);
                    view = inflate;
                    ˎ = ˊ(inflate);
                }
                if (z) {
                    ˎ.ˋ().setVisibility(8);
                } else {
                    ˎ.ˋ().setVisibility(0);
                }
                eqx.ˏ(ˎ.ᐝ(), ˏ.ॱˌ(), "app_default_icon");
                if (AutoCompleteTextAdapter.isOrderApp.equals(ˏ.ˈ())) {
                    ˎ.ˊ().setText(ˏ.ʾ());
                    ˎ.ˎ().setText(ˏ.ʿ());
                    ˎ.ॱॱ().setParam(AutoCompleteTextAdapter.getReserveBtnParam(ˏ));
                    ˎ.ॱॱ().ॱ();
                } else {
                    ˎ.ʼ().setText(ˏ.v_());
                    ˎ.ॱॱ().setParam(a.ˎ(ˏ));
                    ˎ.ॱॱ().ॱ();
                    ˎ.ॱॱ().setSearchListener(bVar);
                    ˋ(ˎ.ʻ(), ˏ);
                    ˊ(ˎ.ˊ(), ˏ.ˋʻ());
                    if (TextUtils.isEmpty(ˏ.ˋॱ())) {
                        ˎ.ʽ().setVisibility(8);
                        ˎ.ʽ().setText("");
                    } else {
                        ˎ.ʽ().setVisibility(0);
                        ˎ.ʽ().setText(ˏ.ˋॱ());
                    }
                    if (ˎ.ॱ() != null) {
                        if (ˏ.ˉ() == null || TextUtils.isEmpty(ˏ.ˉ().ˋ())) {
                            ˎ.ॱ().setVisibility(8);
                        } else {
                            ˎ.ॱ().setVisibility(0);
                            eqx.ˏ(ˎ.ॱ(), ˏ.ˉ().ˋ(), "iconflag");
                        }
                    }
                }
            }
            return view;
        }

        private static void ˊ(TextView textView, String str) {
            if (textView != null) {
                if (TextUtils.isEmpty(str)) {
                    textView.setVisibility(8);
                    return;
                }
                textView.setVisibility(0);
                textView.setText(str);
            }
        }

        private static void ˋ(ImageView imageView, AppInfoBean appInfoBean) {
            String ˏ = a.ॱ(appInfoBean);
            if (ˏ != null) {
                imageView.setVisibility(0);
                eqx.ˏ(imageView, ˏ, "iconflag");
                return;
            }
            imageView.setVisibility(8);
        }

        private static e ˊ(View view) {
            e eVar = new e();
            eVar.ॱ((ImageView) view.findViewById(cuv.b.ˏˎ));
            azb.ॱ(eVar.ᐝ());
            azb.ˋ(view, cuv.b.ـ);
            eVar.ˊ((ImageView) view.findViewById(cuv.b.ॱ));
            eVar.ˋ((TextView) view.findViewById(cuv.b.ꜟ));
            eVar.ॱ((TextView) view.findViewById(cuv.b.ॱʻ));
            eVar.ˊ((TextView) view.findViewById(cuv.b.ˌ));
            eVar.ˎ((AutoSearchDownloadButton) view.findViewById(cuv.b.ᐝˋ));
            eVar.ˋ((ImageView) view.findViewById(cuv.b.ˉ));
            eVar.ˏ((ImageView) view.findViewById(cuv.b.ˏˏ));
            azb.ʻ(eVar.ˋ());
            return eVar;
        }

        private static e ˎ(View view) {
            e eVar = new e();
            eVar.ॱ((ImageView) view.findViewById(cuv.b.ˊᐝ));
            azb.ॱ(eVar.ᐝ());
            azb.ˋ(view, cuv.b.ᐝᐝ);
            eVar.ˋ((TextView) view.findViewById(cuv.b.ㆍ));
            eVar.ˏ((TextView) view.findViewById(cuv.b.ᐧ));
            eVar.ˎ((AutoSearchDownloadButton) view.findViewById(cuv.b.ˊ));
            eVar.ˏ((ImageView) view.findViewById(cuv.b.ᐨ));
            azb.ʻ(eVar.ˋ());
            return eVar;
        }
    }

    static class e {
        private ImageView ʻ;
        private TextView ʼ;
        private TextView ʽ;
        private TextView ˊ;
        private ImageView ˋ;
        private ImageView ˎ;
        private TextView ˏ;
        private ImageView ॱ;
        private AutoSearchDownloadButton ॱॱ;
        private TextView ᐝ;

        private e() {
        }

        private ImageView ˋ() {
            return this.ॱ;
        }

        private void ˏ(ImageView imageView) {
            this.ॱ = imageView;
        }

        private TextView ˏ() {
            return this.ˊ;
        }

        private void ˎ(TextView textView) {
            this.ˊ = textView;
        }

        private ImageView ᐝ() {
            return this.ˋ;
        }

        private void ॱ(ImageView imageView) {
            this.ˋ = imageView;
        }

        private ImageView ʻ() {
            return this.ˎ;
        }

        private void ˊ(ImageView imageView) {
            this.ˎ = imageView;
        }

        private TextView ʼ() {
            return this.ˏ;
        }

        private void ॱ(TextView textView) {
            this.ˏ = textView;
        }

        private TextView ʽ() {
            return this.ᐝ;
        }

        private void ˊ(TextView textView) {
            this.ᐝ = textView;
        }

        private AutoSearchDownloadButton ॱॱ() {
            return this.ॱॱ;
        }

        private void ˎ(AutoSearchDownloadButton autoSearchDownloadButton) {
            this.ॱॱ = autoSearchDownloadButton;
        }

        public TextView ˊ() {
            return this.ʽ;
        }

        public void ˋ(TextView textView) {
            this.ʽ = textView;
        }

        public TextView ˎ() {
            return this.ʼ;
        }

        public void ˏ(TextView textView) {
            this.ʼ = textView;
        }

        public ImageView ॱ() {
            return this.ʻ;
        }

        public void ˋ(ImageView imageView) {
            this.ʻ = imageView;
        }
    }

    public AutoCompleteTextAdapter(Activity activity) {
        setmActivity(activity);
        setmFilteredList(new ArrayList());
        setmInflater(LayoutInflater.from(getmActivity()));
    }

    public void setSearchListener(b bVar) {
        this.listener = bVar;
    }

    private static OrderAppCardBean getReserveBtnParam(AppInfoBean appInfoBean) {
        OrderAppCardBean orderAppCardBean = new OrderAppCardBean();
        orderAppCardBean.ʽ(appInfoBean.ˊˋ());
        orderAppCardBean.ˏˎ(appInfoBean.ॱـ());
        orderAppCardBean.ˉ(appInfoBean.ʼॱ());
        orderAppCardBean.ॱˊ(appInfoBean.ˋˊ());
        orderAppCardBean.ˏॱ(appInfoBean.ᐝॱ());
        orderAppCardBean.ˋॱ(appInfoBean.ॱᐝ());
        orderAppCardBean.ˏ(appInfoBean.ʼ());
        orderAppCardBean.ʻ(appInfoBean.ˊˊ());
        try {
            orderAppCardBean.ॱ(Long.parseLong(appInfoBean.ॱˋ()));
        } catch (NumberFormatException e) {
            cux.ˏ.ˎ(TAG, "NumberFormatException on getReserveBtnParam!");
        }
        orderAppCardBean.ˋᐝ(appInfoBean.ॱˌ());
        orderAppCardBean.ˋ(appInfoBean.v_());
        orderAppCardBean.ˈ(appInfoBean.ʿ());
        orderAppCardBean.ʼॱ(appInfoBean.ʽॱ());
        orderAppCardBean.ॱˎ(appInfoBean.ˊᐝ());
        orderAppCardBean.ˎ(appInfoBean.ॱ());
        orderAppCardBean.ˊ(appInfoBean.ˎˎ());
        orderAppCardBean.ˎ(appInfoBean.ˋˋ());
        orderAppCardBean.ॱ(appInfoBean.ˊ());
        orderAppCardBean.ͺ(appInfoBean.ॱᶥ());
        orderAppCardBean.showDisclaimer_ = appInfoBean.showDisclaimer_;
        orderAppCardBean.gplinkPkgName_ = appInfoBean.gplinkPkgName_;
        orderAppCardBean.webApp_ = appInfoBean.webApp_;
        orderAppCardBean.genShortcutForWebApp_ = appInfoBean.genShortcutForWebApp_;
        orderAppCardBean.jumpToGpOnGMSDevice_ = appInfoBean.jumpToGpOnGMSDevice_;
        orderAppCardBean.detailType_ = appInfoBean.detailType_;
        orderAppCardBean.showDetailUrl_ = appInfoBean.showDetailUrl_;
        orderAppCardBean.ʿ(appInfoBean.ˎͺ());
        ReserveDbInfo ˋ = ((cde) cdb.ॱ(cde.class)).ˋ(appInfoBean.ॱـ());
        if (ˋ != null) {
            orderAppCardBean.ˏॱ(ˋ.ͺ());
            orderAppCardBean.ˋॱ(ˋ.ॱˎ());
            orderAppCardBean.ॱ(ˋ.ॱᐝ());
            orderAppCardBean.ˏॱ(1);
            orderAppCardBean.ˋ(ˋ.ˎ());
            orderAppCardBean.ˋᐝ(ˋ.ᐝ());
            orderAppCardBean.ˎ(ˋ.ॱˋ());
        } else {
            orderAppCardBean.ˏॱ(0);
        }
        return orderAppCardBean;
    }

    public int getCount() {
        if (getmFilteredList() != null) {
            return getmFilteredList().size();
        }
        return 0;
    }

    public Object getItem(int i) {
        return getmFilteredList().get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        cvc searchWordItem = getSearchWordItem(i);
        if (searchWordItem == null) {
            return view;
        }
        boolean z = i == getCount() + -1;
        if (searchWordItem.ˏ() == null) {
            return c.ˊ(searchWordItem, getmInflater(), getmKeyword(), z);
        }
        return c.ॱ(searchWordItem, getmInflater(), z, this.listener);
    }

    private cvc getSearchWordItem(int i) {
        if (getmFilteredList() == null || i >= getmFilteredList().size()) {
            return null;
        }
        return (cvc) getmFilteredList().get(i);
    }

    public void clearCache() {
        if (getmFilteredList() != null) {
            getmFilteredList().clear();
        }
    }

    public void addData(cvc o_cvc) {
        if (getmFilteredList() != null) {
            getmFilteredList().add(o_cvc);
        }
    }

    public boolean isFilteredListEmpty() {
        return getmFilteredList().isEmpty();
    }

    public List<cvc> getmFilteredList() {
        return this.mFilteredList;
    }

    public void setmFilteredList(List<cvc> list) {
        this.mFilteredList = list;
    }

    private LayoutInflater getmInflater() {
        return this.mInflater;
    }

    private void setmInflater(LayoutInflater layoutInflater) {
        this.mInflater = layoutInflater;
    }

    private Activity getmActivity() {
        return this.mActivity;
    }

    private void setmActivity(Activity activity) {
        this.mActivity = activity;
    }

    private String getmKeyword() {
        return this.mKeyword;
    }

    public void setmKeyword(String str) {
        this.mKeyword = str;
    }
}
